import Vue from 'vue'

const templateIds = [
	// 审批结果通知
	'SjcJBrQH_ildMhxf72D3hIqVuVvxqmtlCyU_b-jJark',
]

const appletAuthorize = () => {
	let tmplIds = []
	uni.getStorage({
		key: "currAuthorizeStep",
		success: ({
			data
		}) => {
			console.log("currAuthorizeStep", data);
			let temp = data
			for (var i = 0; i < 3; i++) {
				if (temp === templateIds.length) {
					temp = 0
				}
				tmplIds.push(templateIds[temp])
				temp++
			}
			uni.setStorage({
				key: "currAuthorizeStep",
				data: temp,
				success: (result) => {},
				fail: (error) => {},
			});
			if (tmplIds.length === 0) {
				return
			}

			wx.requestSubscribeMessage({
				tmplIds: tmplIds,
				success(res) {
					console.log("订阅消息唤起成功 =====>", res)
				},
				fail(err) {
					console.log("订阅消息唤起失败 =====>", err)
				}
			})
		},
		fail: (error) => {},
	});
};

Vue.prototype.$appletAuthorize = appletAuthorize

export default appletAuthorize;